/**
 * Created by wzh on 2016/8/6.
 */
swan_pc
    .factory('OrgCompany', function ($resource, DateUtils) {
        return $resource('/api/orgCompanys/:infoid', {infoid:'@infoid',parentId:'@parentId'}, {
            'query': { method: 'GET', isArray: true},
            'queryAll': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    data.companyBaseInfo.foundDate = DateUtils.convertLocaleDateFromServer(data.companyBaseInfo.foundDate);
                    if (data.companyBaseInfo.name.indexOf("^")>=0) data.companyBaseInfo.name=data.companyBaseInfo.name.substr(1)
                    return data;
                }
            },
            'update': {
                method: 'PUT',
                transformRequest: function (data) {
                    if (data.companyBaseInfo.foundDate) data.companyBaseInfo.foundDate = DateUtils.convertLocaleDateToServer(data.companyBaseInfo.foundDate);
                    return angular.toJson(data);
                }
            },
            'save': {
                method: 'POST',
                transformRequest: function (data) {
                    data.companyBaseInfo.foundDate= DateUtils.convertLocaleDateToServer(data.companyBaseInfo.foundDate);
                    return angular.toJson(data);
                }
            },
            'delete':{
                method:'DELETE'
            },
            'queryByOrganizationAndNullParent':{ method: 'GET', isArray: true, url:'api/organizations/:infoid/orgCompanysOfNullParent'},
            'queryByOrgnization': { method: 'GET', isArray: true, url:'api/organizations/:infoid/orgCompanys'},
            'queryByOrgnizationPaging': { method: 'GET', isArray: true, url:'api/organizations/:infoid/orgCompanysPaging'},
            'queryAllTopCompanyByOrgnization': { method: 'GET', isArray: true, url:'api/organizations/:infoid/topOrgCompanys'},
            'updateWithParent':{method: 'PUT',url:'api/orgCompanys/:infoid/parentCompany/:parentId'},
        });
    })
    .factory('Department', function ($resource, DateUtils) {
        return $resource('/api/departments/:infoid', {infoid:'@infoid'}, {
            'query': { method: 'GET', isArray: true},
            'queryAll': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    //data.companyBaseInfo.foundDate = DateUtils.convertLocaleDateFromServer(data.companyBaseInfo.foundDate);
                    return data;
                }
            },
            'update': {
                method: 'PUT',
                transformRequest: function (data) {
                    //data.companyBaseInfo.foundDate = DateUtils.convertLocaleDateToServer(data.companyBaseInfo.foundDate);
                    return angular.toJson(data);
                }
            },
            'save': {
                method: 'POST',
                transformRequest: function (data) {
                    //data.companyBaseInfo.foundDate= DateUtils.convertLocaleDateToServer(data.companyBaseInfo.foundDate);
                    return angular.toJson(data);
                }
            },
            'delete':{
                method:'DELETE'
            },
        });
    })
    .factory('Address', function ($resource, DateUtils) {
        return $resource('/api/addresss/:infoid', {infoid:'@infoid'}, {
            'query': { method: 'GET', isArray: true},
            'queryAll': {
                method: 'GET',
                transformResponse: function (data) {
                    data = angular.fromJson(data);
                    return data;
                }
            },
            'update': {
                method: 'PUT',
                transformRequest: function (data) {
                    return angular.toJson(data);
                }
            },
            'save': {
                method: 'POST',
                transformRequest: function (data) {
                    return angular.toJson(data);
                }
            },
            'delete':{
                method:'DELETE'
            },
        });
    });